﻿using System;

public class BubbleSort
{
    public static void Sort(int[] arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n - 1; i++)
        {
            // 每轮排序后最大的元素会"浮"到末尾
            for (int j = 0; j < n - i - 1; j++)
            {
                // 如果当前元素大于下一个元素，则交换
                if (arr[j] > arr[j + 1])
                {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    public static void Main()
    {
        int[] arr = { 64, 34, 25, 12, 22, 11, 90 };
        Console.WriteLine("排序前的数组:");
        foreach (int num in arr)
        {
            Console.Write(num + " ");
        }

        Sort(arr);

        Console.WriteLine("\n排序后的数组:");
        foreach (int num in arr)
        {
            Console.Write(num + " ");
        }
    }
}